package com.water.weatherservice.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * @author 汪胜彬
 * @version 1.0
 */
@Service
@Slf4j
public class WeatherService {

    @Value("${baidu.host}")
    private String host;
    @Value("${baidu.method}")
    private String method;
    @Value("${baidu.ak}")
    private String ak;
    private String district_id;
    private String args;

    @Resource
    @Qualifier("getRestTemplateNoLB")
    RestTemplate restTemplate;
    @Resource
    LocationService locationService;

    public String getWeather(){
        district_id = locationService.getAdcode();
        args =  "ak=" + ak + "&district_id=" + district_id + "&data_type=all";
        String url = host + "/" + method + "/?" + args;
        log.info(url);
        return restTemplate.getForObject(url, String.class);
    }
}
